/*
 * Copyright 2008-2011 Wyld Collective / Obx Labs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

/**
 * SimpleUrlFeed
 *
 * This example shows the simplest way to get data from a syndicated
 * feed (RSS or ATOM) from a URL. The sketch fetches information
 * from a feed and print out its entries to the console.
 */

//romefeeder
import com.wyldco.romefeeder.*;
import com.sun.syndication.feed.synd.*;

Feeder feeder;         // the feeder
SyndEntry entry;       // a feed entry

void setup() {
  //create the feeder
  feeder = new Feeder(this);

  //turn on output to the console (useful for debugging)
  feeder.verbose = true;

  //set sort by published date
  //default is unsorted (i.e. as ordered in the feed)
  feeder.sortByPublishedDate();

  //if you are exporting your sketch to an applet
  //set the proxy to bypass applet domain limitations
  //make sure you copy the proxy.php provided in the
  //data folder of this example to your applet directory
  //feeder.setProxy("http://[urlToApplet]/SimpleUrlFeed/applet/proxy.php");
  
  //load the feed  
  feeder.load("http://www.rssboard.org/files/sample-rss-2.xml");
}

void draw() {
  //display the next entries
  while (feeder.hasNext()) {
    //get the next entry
    entry = feeder.next();
    println("\n" + entry.getTitle());
    println(" + " + entry.getPublishedDate());
    println(" + " + entry.getLink());
    println(" + " + entry.getDescription().getValue());
  }
}